package com.zmykj.hik.hikService.Service.CMS;

import com.zmykj.hik.hikService.Common.CommonClass;
import com.sun.jna.*;

import com.zmykj.hik.hikService.Common.CommonClass.NET_EHOME_DEV_SESSIONKEY;
import com.zmykj.hik.hikService.Common.CommonClass.NET_EHOME_IPADDRESS;

import java.util.Arrays;
import java.util.List;

public interface ISUPCMSByJNA extends Library{
 
 
    public static final int ENUM_DEV_ON = 0;
    public static final int ENUM_DEV_OFF = 1;
    public static final int ENUM_DEV_ADDRESS_CHANGED = 2;
    public static final int ENUM_DEV_AUTH = 3;
    public static final int ENUM_DEV_SESSIONKEY = 4;
    public static final int ENUM_DEV_DAS_REQ = 5;
    public static final int ENUM_DEV_DAS_REREGISTER = 7;
    public static final int ENUM_DEV_DAS_EHOMEKEY_ERROR = 9;
    public static final int ENUM_DEV_SESSIONKEY_ERROR = 10;
    public static final int ACTIVE_ACCESS_SECURITY = 0;
    public static final int AMS_ADDRESS = 1;
    public static final int SEND_PARAM = 2;
    
    
 
    public static final int NET_EHOME_GET_DEVICE_INFO     = 1;
    public static final int NET_EHOME_GET_VERSION_INFO    = 2; 
    public static final int NET_EHOME_GET_DEVICE_CFG      = 3; 
    public static final int NET_EHOME_SET_DEVICE_CFG      = 4; 
    public static final int NET_EHOME_GET_COMPRESSION_CFG = 7; 
    public static final int NET_EHOME_SET_COMPRESSION_CFG = 7; 

    public static final int NET_EHOME_GET_GPS_CFG           = 20; 
    public static final int NET_EHOME_SET_GPS_CFG           = 21; 
    public static final int NET_EHOME_GET_PIC_CFG           = 22; 
    public static final int NET_EHOME_SET_PIC_CFG           = 23; 
    public static final int NET_EHOME_GET_NETWORK_CFG       = 5;
    public static final int NET_EHOME_SET_NETWORK_CFG       = 6;
    public static final int NET_EHOME_GET_WIRELESSINFO_CFG  = 24; 
    public static final int NET_EHOME_SET_WIRELESSINFO_CFG  = 25; 

 
    public static interface NET_EHOME_REGISTER_TYPE
    {
        public final int ENUM_UNKNOWN                = -1;
        public final int ENUM_DEV_ON                 = 0; 
        public final int ENUM_DEV_OFF                = 1; 
        public final int ENUM_DEV_ADDRESS_CHANGED    = 2; 
        public final int ENUM_DEV_AUTH               = 3; 
        public final int ENUM_DEV_SESSIONKEY         = 4; 
        public final int ENUM_DEV_DAS_REQ            = 5; 
        public final int ENUM_DEV_SESSIONKEY_REQ     = 6; 
        public final int ENUM_DEV_DAS_REREGISTER     = 7; 
        public final int ENUM_DEV_DAS_PINGREO        = 8; 
        public final int ENUM_DEV_DAS_EHOMEKEY_ERROR = 9; 
    }

    public static class  NET_EHOME_CMSCB_DATA extends Structure
    {
        public NativeLong   lUserID; 
        public int  dwType; 
        public int  dwHandle; 
        boolean   bSucc; 
        public Pointer pOutBuffer; 
        public int  dwOutLen; 
        public int  dwErrorNo; 
        public byte[]   byRes = new byte[32]; 
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("lUserID", "dwType","dwHandle", "bSucc", "pOutBuffer","dwOutLen","dwErrorNo","byRes");
        }
    }

    public static class NET_EHOME_DEV_REG_INFO extends Structure {
        public int dwSize;
        public int dwNetUnitType;
        public byte[] byDeviceID = new byte[CommonClass.MAX_DEVICE_ID_LEN];
        public byte[] byFirmwareVersion = new byte[24];
        public NET_EHOME_IPADDRESS struDevAdd;
        public int dwDevType;
        public int dwManufacture;
        public byte[] byPassWord = new byte[32];
        public byte[] sDeviceSerial = new byte[CommonClass.NET_EHOME_SERIAL_LEN];
        public byte byReliableTransmission;
        public byte   byWebSocketTransmission;
        public byte   bySupportRedirect; 
        public byte[] byDevProtocolVersion = new byte[6]; 
        public byte[] bySessionKey = new byte[16]; 
        public byte   byMarketType; 
        public byte[] byRes = new byte[26];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize", "dwNetUnitType","byDeviceID", "byFirmwareVersion",
                    "struDevAdd", "dwDevType","dwManufacture","byPassWord", "sDeviceSerial",
                    "byReliableTransmission", "byWebSocketTransmission", "bySupportRedirect",
                    "byDevProtocolVersion", "bySessionKey", "byMarketType", "byRes");
        }
    }

    public static class NET_EHOME_DEV_REG_INFO_V12 extends Structure {
        public NET_EHOME_DEV_REG_INFO struRegInfo;
        public NET_EHOME_IPADDRESS struRegAddr;
        public byte[] sDevName = new byte[CommonClass.MAX_DEVNAME_LEN];
        public byte[] byDeviceFullSerial = new byte[CommonClass.MAX_FULL_SERIAL_NUM_LEN];
        public byte[] byRes = new byte[128];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("struRegInfo", "struRegAddr", "sDevName", "byDeviceFullSerial", "byRes");
        }
    }

    public static class NET_EHOME_BLACKLIST_SEVER extends Structure {
        public NET_EHOME_IPADDRESS struAdd;
        public byte[] byServerName = new byte[32];
        public byte[] byUserName = new byte[32];
        public byte[] byPassWord = new byte[32];
        public byte[] byRes = new byte[64];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("struAdd", "byServerName","byUserName", "byPassWord", "byRes");
        }
    }

    public static class NET_EHOME_SERVER_INFO extends Structure {
        public int dwSize;
        public int dwKeepAliveSec;
        public int dwTimeOutCount;
        public NET_EHOME_IPADDRESS struTCPAlarmSever;
        public NET_EHOME_IPADDRESS struUDPAlarmSever;
        public int dwAlarmServerType;
        public NET_EHOME_IPADDRESS struNTPSever;
        public int dwNTPInterval;
        public NET_EHOME_IPADDRESS struPictureSever;
        public int dwPicServerType;
        public NET_EHOME_BLACKLIST_SEVER struBlackListServer;
        public byte[] byRes = new byte[128];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize", "dwKeepAliveSec","dwTimeOutCount", "struTCPAlarmSever",
                    "struUDPAlarmSever", "dwAlarmServerType","struNTPSever","dwNTPInterval", "struPictureSever",
                    "dwPicServerType", "struBlackListServer", "byRes");
        }
    }
    
    public static class NET_EHOME_VERSION_INFO extends Structure {
    	public int dwSize;
    	public byte[] sSoftwareVersion = new byte[CommonClass.MAX_VERSION_LEN];
    	public byte[] sDSPSoftwareVersion = new byte[CommonClass.MAX_VERSION_LEN];
    	public byte[] sPanelVersion = new byte[CommonClass.MAX_VERSION_LEN];
    	public byte[] sHardwareVersion = new byte[CommonClass.MAX_VERSION_LEN];
    	public byte[] byRes = new byte[124];
    	@Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize", "sSoftwareVersion", "sDSPSoftwareVersion","sPanelVersion", "sHardwareVersion", "byRes");
        }
    }
    
    public static class NET_EHOME_DEVICE_CFG extends Structure
    {
        public int        dwSize; 
        public byte[]     sServerName = new byte[CommonClass.MAX_DEVICE_NAME_LEN];
        public int        dwServerID; 
        public int        dwRecycleRecord; 
        public int        dwServerType; 
        public int        dwChannelNum; 
        public int        dwHardDiskNum; 
        public int        dwAlarmInNum; 
        public int        dwAlarmOutNum; 
        public int        dwRS232Num; 
        public int        dwRS485Num; 
        public int        dwNetworkPortNum; 
        public int        dwAuxoutNum; 
        public int        dwAudioNum; 
        public byte[]     sSerialNumber = new byte[CommonClass.MAX_SERIALNO_LEN];
        public int        dwMajorScale; 
        public int        dwMinorScale; 
        public byte[]     byRes = new byte[292]; 
        protected List<String> getFieldOrder(){
        return Arrays.asList("dwSize","sServerName","dwServerID","dwRecycleRecord","dwServerType","dwChannelNum",
        		"dwHardDiskNum","dwAlarmInNum","dwAlarmOutNum","dwRS232Num","dwRS485Num","dwNetworkPortNum",
        		"dwAuxoutNum","dwAudioNum","sSerialNumber","dwMajorScale","dwMinorScale","byRes");
      }
    }

    public static class NET_EHOME_COMPRESSION_CFG extends Structure
    {
        public int       dwSize; 
        public byte        byStreamType; 
        public byte        byPicQuality; 
        public byte        byBitRateType; 
        public byte        byRes1; 
        public int       dwResolution;
        public int       dwVideoBitRate;     
        public int       dwMaxBitRate; 
        public int       dwVideoFrameRate; 
        public short        wIntervalFrameI; 
        public byte        byIntervalBPFrame; 
        public byte[]        byRes = new byte[41]; 
        protected List<String> getFieldOrder(){
        return Arrays.asList("dwSize","byStreamType","byPicQuality","byBitRateType","byRes1","dwResolution",
        		"dwVideoBitRate","dwMaxBitRate","dwVideoFrameRate","wIntervalFrameI","byIntervalBPFrame","byRes");
      }
    }
    
    public static class NET_EHOME_COMPRESSION_COND extends Structure
    {
    	public int dwSize;
    	public int dwChannelNum;
    	public byte byCompressionType;
    	public byte[] byRes = new byte[23];
    	protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize","dwChannelNum","byCompressionType","byRes");
        }
    }
    
    public static class NET_EHOME_PIC_CFG extends Structure
    {
        public int           	dwSize;
        public byte[]        	byChannelName = new byte[32]; 
        public byte            	bIsShowChanName; 
        public short            wChanNameXPos; 
        public short            wChanNameYPos; 
        public byte             bIsShowOSD; 
        public short            wOSDXPos; 
        public short            wOSDYPos; 
        public byte             byOSDType; 
 
        public byte             byOSDAtrib; 
        public byte[]           byRes1 = new byte[2]; 
        public byte             bIsShowWeek; 
        public byte[]           byRes2 = new byte[64]; 
        protected List<String> getFieldOrder(){
        return Arrays.asList("dwSize","byChannelName","bIsShowChanName", "wChanNameXPos","wChanNameYPos",
        		"bIsShowOSD", "wOSDXPos","wOSDYPos","byOSDType","byOSDAtrib","byRes1","bIsShowWeek", "byRes2");
      }
    }
    
    public static class NET_EHOME_PREVIEWINFO_IN_V11 extends Structure{
        public int iChannel;
        public int dwStreamType;
        public int dwLinkMode;
        public NET_EHOME_IPADDRESS    struStreamSever;
        public byte byDelayPreview;
        public byte[] byRes=new byte[31];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("iChannel", "dwStreamType","dwLinkMode", "struStreamSever",
                    "byDelayPreview", "byRes");
        }
    }

    public static class NET_EHOME_PREVIEWINFO_OUT extends Structure
    {
        public NativeLong  lSessionID;
        public NativeLong  lHandle; 
        public byte[]  byRes = new byte[124];
        protected List<String> getFieldOrder(){
            return Arrays.asList("lSessionID", "lHandle", "byRes");
        }
    }

    public static class NET_EHOME_PUSHSTREAM_IN extends Structure
    {
        public int dwSize;
        public NativeLong  lSessionID;
        public byte[]  byRes = new byte[128];
        protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize", "lSessionID", "byRes");
        }
    }

    public static class NET_EHOME_PUSHSTREAM_OUT extends Structure
    {
        public int dwSize;
        public NativeLong lHandle; 
        public byte[]  byRes = new byte[124];
        protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize", "lHandle", "byRes");
        }
    }

    public interface VoiceDataCallBack extends Callback{
        public void invoke(int iVoiceComHandle, Pointer pRecvDataBuffer, int dwBufSize, int dwEncodeType,
                           byte byAudioFlag, Pointer pUser);
    }

    public interface DEVICE_REGISTER_CB extends Callback {
        public boolean invoke(NativeLong lUserID, int dwDataType, Pointer pOutBuffer,
                              int dwOutLen, Pointer pInBuffer, int dwInLen, Pointer pUser);

    }

    public static class NET_EHOME_CMS_LISTEN_PARAM extends Structure {
        public NET_EHOME_IPADDRESS struAddress;
        public DEVICE_REGISTER_CB fnCB;
        public Pointer pUserData;
        public byte[] byRes = new byte[32];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("struAddress", "fnCB","pUserData", "byRes");
        }
    }
    
    public static class NET_EHOME_DEV_SESSIONKEY_EHOME50 extends Structure{
    	public byte[] sDeviceID   = new byte[256];
    	public byte[] sSessionKey = new byte[16];
    	@Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("sDeviceID", "sSessionKey");
        }
    }

     
    public static class NET_EHOME_XML_CFG extends Structure
    {
        public Pointer pCmdBuf; 
        public int      dwCmdLen; 
        public Pointer pInBuf; 
        public int      dwInSize; 
        public Pointer pOutBuf; 
        public int      dwOutSize; 
        public int      dwSendTimeOut; 
        public int      dwRecvTimeOut; 
        public Pointer pStatusBuf; 
        public int      dwStatusSize; 
        public byte[]       byRes = new byte[24];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("pCmdBuf","dwCmdLen","pInBuf","dwInSize","pOutBuf","dwOutSize","dwSendTimeOut",
                    "dwRecvTimeOut","pStatusBuf","dwStatusSize","byRes");
        }
    }

    public static class NET_EHOME_PTXML_PARAM extends Structure
    {
        public Pointer pRequestUrl; 
        public int   dwRequestUrlLen; 
        public Pointer pCondBuffer; 
        public int   dwCondSize; 
        public Pointer pInBuffer; 
        public int   dwInSize; 
        public Pointer pOutBuffer; 
        public int   dwOutSize; 
        public int   dwReturnedXMLLen; 
        public int   dwRecvTimeOut; 
        public int   dwHandle; 
        public byte[]    byRes = new byte[24]; 
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("pRequestUrl","dwRequestUrlLen","pCondBuffer","dwCondSize","pInBuffer","dwInSize",
                    "pOutBuffer","dwOutSize","dwReturnedXMLLen","dwRecvTimeOut","dwHandle","byRes");
        }
    }

    public static class NET_EHOME_XML_REMOTE_CTRL_PARAM extends Structure
    {
        public int dwSize;
        public Pointer lpInbuffer; 
        public int dwInBufferSize; 
        public int dwSendTimeOut; 
        public int dwRecvTimeOut; 
        public Pointer lpOutBuffer; 
        public int dwOutBufferSize; 
        public Pointer lpStatusBuffer; 
        public int dwStatusBufferSize; 
        public byte[]  byRes = new byte[16];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize","lpInbuffer","dwInBufferSize","dwSendTimeOut","dwRecvTimeOut",
                    "lpOutBuffer","dwOutBufferSize","lpStatusBuffer","dwStatusBufferSize","byRes");
        }
    }
    
    public static class NET_EHOME_CONFIG extends Structure{  
        public Pointer pCondBuf;  
        public int    dwCondSize;  
        public Pointer pInBuf;
        public int    dwInSize;  
        public Pointer pOutBuf; 
        public int    dwOutSize;
        public byte[] byRes = new byte[40];
        @Override
        protected List<String> getFieldOrder(){
            return Arrays.asList("pCondBuf","dwCondSize","pInBuf","dwInSize","pOutBuf",
                    "dwOutSize","byRes");
        }
    }
    
    public static class NET_EHOME_DEVICE_INFO extends Structure{  
        public int    dwSize;  
        public int    dwChannelNumber; 
        public int    dwChannelAmount;
        public int    dwDevType;  
        public int    dwDiskNumber;
        public byte[] sSerialNumber = new byte[128];  
        public int    dwAlarmInPortNum;
        public int    dwAlarmInAmount; 
        public int    dwAlarmOutPortNum;
        public int    dwAlarmOutAmount;  
        public int    dwStartChannel;  
        public int    dwAudioChanNum;
        public int    dwMaxDigitChannelNum;  
        public int    dwAudioEncType;
        public byte[] sSIMCardSN = new byte[128];
        public byte[]   sSIMCardPhoneNum = new byte[32];  
        public int    dwSupportZeroChan;
        public int    dwStartZeroChan;  
        public int    dwSmartType;  
        public byte[] byRes = new byte[160];
		@Override
		protected List<String> getFieldOrder() {
			return Arrays.asList("dwSize","dwChannelNumber","dwChannelAmount","dwDevType","dwDiskNumber",
                    "sSerialNumber","dwAlarmInPortNum", "dwAlarmInAmount", "dwAlarmOutPortNum", 
                    "dwAlarmOutAmount", "dwStartChannel", "dwAudioChanNum", "dwMaxDigitChannelNum", 
                    "dwAudioEncType", "sSIMCardSN", "sSIMCardPhoneNum", "dwSupportZeroChan", "dwStartZeroChan",
                    "dwSmartType", "byRes");
		}
    };
    
    public static final int MACADDR_LEN = 6;
    public static final int NAME_LEN = 32;
    public static final int PASSWD_LEN = 16;
    
    public static class NET_EHOME_IPADDR extends Structure
    {
        public byte[]    sIpV4 = new byte[16];
        public byte[]    sIpV6 = new byte[128];
        protected List<String> getFieldOrder(){
        return Arrays.asList("sIpV4", "sIpV6");
      }
    }
    
    public static class NET_EHOME_ETHERNET extends Structure
    {
        public NET_EHOME_IPADDR    struDevIP; 
        public NET_EHOME_IPADDR    struDevIPMask; 
        public int               dwNetInterface; 
        public short                wDevPort; 
        public short                wMTU; 
        public byte[]                byMACAddr = new byte[MACADDR_LEN]; 
        public byte[]                byRes = new byte[2];
        
        protected List<String> getFieldOrder(){
        return Arrays.asList("struDevIP","struDevIPMask","dwNetInterface","wDevPort","wMTU","byMACAddr","byRes");
      }
    }

    public static class NET_EHOME_PPPOECFG extends Structure
    {
    	public int dwPPPoE;
    	public byte[] sPPPoEUser = new byte[NAME_LEN];
    	public byte[] sPPPoEPassword = new byte[PASSWD_LEN];
    	public NET_EHOME_IPADDR struPPPoEIP;
    	
    	protected List<String> getFieldOrder(){
            return Arrays.asList("dwPPPoE","sPPPoEUser","sPPPoEPassword","struPPPoEIP");
          }
    }
    
    public static class NET_EHOME_NETWORK_CFG extends Structure
    {
    	public int dwSize;
    	public NET_EHOME_ETHERNET struEtherNet;
    	public NET_EHOME_IPADDR struGateWayIP;
    	public NET_EHOME_IPADDR struMultiCastIP;
    	public NET_EHOME_IPADDR struDDNSServer1IP;
    	public NET_EHOME_IPADDR struDDNSServer2IP;
    	public NET_EHOME_IPADDR struAlarmHostIP;
    	public short wAlarmHostPort;
    	public short wIPResolverPort;
    	public NET_EHOME_IPADDR struIPResolver;
    	public NET_EHOME_PPPOECFG  struPPPoE;
    	public short wHTTPPort;
    	public byte[] byRes = new byte[674];
    	
    	protected List<String> getFieldOrder(){
            return Arrays.asList("dwSize","struEtherNet","struGateWayIP","struMultiCastIP", "struDDNSServer1IP",
            		"struDDNSServer2IP", "struAlarmHostIP", "wAlarmHostPort", "wIPResolverPort", "struIPResolver",
            		"struPPPoE", "wHTTPPort", "byRes");
          }
    }

    public static class NET_EHOME_VOICETALK_PARA extends Structure
    {
        public boolean bNeedCBNoEncData;
        public VoiceDataCallBack fVoiceDataCallBack;
        public int dwEncodeType;
        public Pointer pUser;
        public byte byVoiceTalk;
        public byte byDevAudioEnc;
        public byte[] byRes1 = new byte[2];
        public NativeLong lHandle;
        public byte[] byRes = new byte[56];

        protected List<String> getFieldOrder(){
            return Arrays.asList("bNeedCBNoEncData", "fVoiceDataCallBack", "dwEncodeType", "pUser", "byVoiceTalk",
                    "byDevAudioEnc", "byRes1", "lHandle", "byRes");
        }
    }
 
    public boolean NET_ECMS_Init();

 
    public int NET_ECMS_GetBuildVersion();

 
    public boolean NET_ECMS_SetSDKLocalCfg(int enumType, Pointer lpInBuff);
    public boolean NET_ECMS_GetSDKLocalCfg(int enumType, Pointer lpOutBuff);
    public boolean NET_ECMS_GetDevConfig(NativeLong lUserID, int dwCommand, NET_EHOME_CONFIG lpConfig, int dwConfigSize);
    public boolean NET_ECMS_SetDevConfig(NativeLong lUserID, int dwCommand, Pointer lpConfig, int dwConfigSize);
 
    public NativeLong NET_ECMS_StartListen(NET_EHOME_CMS_LISTEN_PARAM lpCMSListenPara);
    
 
    public boolean NET_ECMS_StopListen(NativeLong lHandle);

    public boolean NET_ECMS_ForceLogout(NativeLong lUserID);

    public boolean NET_ECMS_SetLogToFile(long lLogLevel, String strLogDir, boolean bAutoDel);

    public NativeLong NET_ECMS_StartVoiceTalk(NativeLong lUserID, int dwVoiceChan, NET_EHOME_VOICETALK_PARA pVoiceTalkPara);
    public boolean NET_ECMS_SendVoiceTransData(NativeLong lUserID, Pointer pSendBuf, int dwBufSize);
    public boolean NET_ECMS_StopVoiceTalk(NativeLong iVoiceHandle);

    public int NET_ECMS_GetLastError();

    public boolean NET_ECMS_Fini();

    public boolean NET_ECMS_SetDeviceSessionKey(NET_EHOME_DEV_SESSIONKEY pDeviceKey);
    public boolean NET_ECMS_StartGetRealStreamV11(int lUserID, NET_EHOME_PREVIEWINFO_IN_V11 pPreviewInfoIn, Pointer pPreviewInfoOut);
    public boolean NET_ECMS_StartPushRealStream(int lUserID, NET_EHOME_PUSHSTREAM_IN pPushInfoIn, NET_EHOME_PUSHSTREAM_OUT pPushInfoOut);
    public boolean NET_ECMS_StopGetRealStream(long lUserID, long lSessionID);
    public boolean NET_ECMS_XMLConfig(int lUserID, Pointer pXmlCfg, int dwConfigSize);
    public boolean NET_ECMS_GetPTXMLConfig(long lUserID, NET_EHOME_PTXML_PARAM pPTXMLParam);
    public boolean NET_ECMS_PutPTXMLConfig(long lUserID, NET_EHOME_PTXML_PARAM pPTXMLParam);
    public boolean NET_ECMS_PostPTXMLConfig(long lUserID, NET_EHOME_PTXML_PARAM pPTXMLParam);
    public boolean NET_ECMS_DeletePTXMLConfig(long lUserID, NET_EHOME_PTXML_PARAM pPTXMLParam);
    public boolean NET_ECMS_XMLRemoteControl(long lUserID, Pointer lpCtrlParam, int dwCtrlSize);
    public boolean NET_ECMS_ISAPIPassThrough(long lUserID, Pointer lpParam);
}
